using System;
using Habanero.Base;
using Habanero.BO;

namespace FireStarterModeller.BO
{
    public class DMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnce : IBusinessObjectRule
    {
        private readonly DMInheritanceRelationship _inheritanceRelationship;

        public DMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnce(DMInheritanceRelationship inheritanceRelationship)
        {
            if (inheritanceRelationship == null) throw new ArgumentNullException("inheritanceRelationship");
            _inheritanceRelationship = inheritanceRelationship;
        }

        public bool IsValid()
        {
            if (_inheritanceRelationship.Discriminator == null) return false;
            return true;
        }

        public string Name
        {
            get { return "DMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnce"; }
        }

        public string Message
        {
            get { return string.Format("The discriminator for the superclass of '{0}' must be a Property of type 'String' or a CustomType that can be resolved to string", _inheritanceRelationship.SubClass); }
        }

        public ErrorLevel ErrorLevel
        {
            get { return ErrorLevel.Warning; }
        }
    }
}